package server.phone.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONObject;
import server.phone.dao.BillAndPdtDAO;
import server.phone.dao.DeskDAO;

import com.opensymphony.xwork2.ActionSupport;
import com.utopia84.model.Billandpdt;
import com.utopia84.model.Desk;
import com.utopia84.utils.MyDate;

public class SetBillAndPdtServlet extends ActionSupport {
	private static final long serialVersionUID = -7811568044252827351L;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public SetBillAndPdtServlet(){
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
	}

	public void doGet()	throws  IOException, ClassNotFoundException, SQLException {
		response.setContentType("text/html;charset=UTF-8");

		String billId = request.getParameter("billId");
		String pdtCode = request.getParameter("pdtCode");
		String salerecordId = request.getParameter("salerecordId");

		System.out.println("SetBillAndPdtServlet:"+"billId="+billId+",pdtCode="+pdtCode+",salerecordId="+salerecordId);
		BillAndPdtDAO bapd=new BillAndPdtDAO();
		Billandpdt bap=new Billandpdt(billId,salerecordId,pdtCode);
		
		
		
		JSONObject jObject = new JSONObject();
		try {
			if(bapd.Add(bap)==1)
				jObject.put("ret", "success");
			else
				jObject.put("ret", "error");
		} catch (Exception e) {
			jObject.put("ret", "error");
		}

		PrintWriter out = response.getWriter();
		System.out.println(jObject.toString());
		out.println(jObject);
		out.flush();
		out.close();

	}

}
